package com.designpatternspart2.behavioraldesignpatterns.mementopattern;

/**
 *
 * @author Lance
 */
public class DietInfo
{

    private String personName;
    private int dayNumber;
    private int weight;

    public DietInfo(String personName, int dayNumber, int weight)
    {
        this.personName = personName;
        this.dayNumber = dayNumber;
        this.weight = weight;
    }

    @Override
    public String toString()
    {
        return "Name: " + getPersonName() + ",day number: " + getDayNumber() + ",weight: " + getWeight();
    }

    public void setDayNumberAndWeight(int dayNumber, int weight)
    {
        this.setDayNumber(dayNumber);
        this.setWeight(weight);
    }

    public Memento save()
    {
        return new Memento(getPersonName(), getDayNumber(), getWeight());
    }

    public void restore(Object objMemento)
    {
        Memento memento = (Memento) objMemento;
        setPersonName(memento.mementoPersonName);
        setDayNumber(memento.mementoDayNumber);
        setWeight(memento.mementoWeight);
    }
// memento .. object that stores the saved state of the originator

    public String getPersonName()
    {
        return personName;
    }

    public void setPersonName(String personName)
    {
        this.personName = personName;
    }

    public int getDayNumber()
    {
        return dayNumber;
    }

    public void setDayNumber(int dayNumber)
    {
        this.dayNumber = dayNumber;
    }

    public int getWeight()
    {
        return weight;
    }

    public void setWeight(int weight)
    {
        this.weight = weight;
    }

    private class Memento
    {

        String mementoPersonName;
        int mementoDayNumber;
        int mementoWeight;

        public Memento(String personName, int dayNumber, int weight)
        {
            mementoPersonName = personName;
            mementoDayNumber = dayNumber;
            mementoWeight = weight;
        }
    }
}
